package stack;
@SuppressWarnings("unchecked")


public class Stack<Template>  {
	Template[] array = null;
	int currentPos = -1;
	int size = 0;
	public Stack()	{
		array = (Template[]) new Object[1];
		size = 1;
	}
	public Stack(int size)	{
		array = (Template[]) new Object[size];
		this.size=size;
	}

	private void resize()
	{
		Template[] auxArray = (Template[]) new Object[size+100];
		for(int i=0; i<=currentPos; i++)
			auxArray[i]=array[i];
		array = auxArray;
		size= size+100;
	}

	public void push(Template newElement)
	{	
		if (currentPos + 1 < size){
		currentPos++;
		array[currentPos] = newElement;}
		else { 
			resize(); 
			currentPos++;
			array[currentPos] = newElement;}
	}

	public Template peek()
	{
		if (currentPos>=0)
		return array[currentPos];
		else { System.out.println("Peek Index out of bounds" ); return null;}
	}
	
	public Template pop()
	{
		if (currentPos>=0)
		return array[currentPos--];
		else { System.out.println("Pop Index out of bounds" ); return null;}
	}
	
	public Template get(int i)
	{
		if (i<=currentPos)
			return array[i];
		else { System.out.println("Get Index out of bounds" );return null;}
	}
	
	public int size(){
		return currentPos+1;
	}
	
}
